<?php defined('SYSPATH') or die('No direct script access.');

class Controller_Admin_Site extends Controller_Admin_Base {
    
    public function before()
    {
        parent::before();
        if ($this->auto_render)
        {
            $this->template->ptitle="网站管理";
        }
    }
   //首页维护
    public function action_index()
    {
        $this->template->title = __('首页维护');

        $model=new  Model_Admin_Menu();

        $view=View::factory('admin/site/index');

        $view->menuList=$model->getInfo();

        $view->assortList=$model->getAssort();

        $this->template->content =$view ;
    }

    public function action_user(){

        $this->template->title = __('用户维护');

        $user_model=new Model_Admin_SiteUser();

        $name=$this->request->query('name');

        $email=$this->request->query('email');

        $page=$this->request->query("page");

        $pageSize=$this->request->query("pageSize");

        $page=$page==""||$page==0?1:intval($page);

        $pageSize=$pageSize==""?20:intval($pageSize);

        $offset=$pageSize*($page-1);

        $user_info=$user_model->getInfo($name,$email,$offset,$pageSize);

        $pages=ceil((intval($user_info['total']))/$pageSize);

        $view=View::factory('admin/site/user');

        $view->page= $page;

        $view->pages=$pages;

        $view->name=$name;

        $view->email=$email;

        $view->user_info=$user_info;

        $this->template->content =$view ;

    }

    public function action_banner(){

        $model=new Model_Admin_Banner();

        $banner_list=$model->getInfo();

        $this->template->title = __('banner维护');

        $view=View::factory('admin/site/banner');

        $view->banner_list=$banner_list;

        $this->template->content =$view ;
    }
    public function action_country(){

        $model=new Model_Admin_Country();

        $country_list=$model->getInfo();

        $this->template->title = __('国家维护');

        $view=View::factory('admin/site/country');

        $view->country_list=$country_list;

        $this->template->content =$view ;
    }
    //搜索管理
    public function action_search()
    {
        $model=new Model_Admin_Search();

        $keyword=$this->request->query('keyword');

        $username=$this->request->query('username');

        $page=$this->request->query("page");

        $pageSize=$this->request->query("pageSize");

        $page=$page==""||$page==0?1:intval($page);

        $pageSize=$pageSize==""?20:intval($pageSize);

        $offset=$pageSize*($page-1);

        $searchList=$model->getInfo($username,$keyword,$offset,$pageSize);

        $pages=ceil((intval($searchList['total']))/$pageSize);

        $this->template->title = __('分享搜索记录');

       
        $view = View::factory('admin/site/search');

        $view->searchList =$searchList;

        $view->page= $page;

        $view->pages=$pages;

        $view->keyword=$keyword;

        $view->username=$username;

        $this->template->content =  $view;
    }
    //搜索管理
    public function action_tags()
    {
        $model=new Model_Admin_Tag();

        $caption=$this->request->query('caption');

        $username=$this->request->query('username');

        $page=$this->request->query("page");

        $pageSize=$this->request->query("pageSize");

        $page=$page==""||$page==0?1:intval($page);

        $pageSize=$pageSize==""?20:intval($pageSize);

        $offset=$pageSize*($page-1);

        $tagList=$model->getInfo($username,$caption,$offset,$pageSize);

        $pages=ceil((intval($tagList['total']))/$pageSize);

        $this->template->title = __('分享标签');

        $view = View::factory('admin/site/tag');

        $view->tagList =$tagList;

        $view->page= $page;

        $view->pages=$pages;

        $view->caption=$caption;

        $view->username=$username;

        $this->template->content =  $view;
    }

    //搜索管理
    public function action_news()
    {
        Lib_Rss::save();
        $model=new Model_Admin_News();

        $caption=$this->request->query('caption');

        $username=$this->request->query('username');

        $page=$this->request->query("page");

        $pageSize=$this->request->query("pageSize");

        $page=$page==""||$page==0?1:intval($page);

        $pageSize=$pageSize==""?20:intval($pageSize);

        $offset=$pageSize*($page-1);

        $newsList=$model->getInfo($username,$caption,$offset,$pageSize);

        $pages=ceil((intval($newsList['total']))/$pageSize);

        $this->template->title = __('news');

        $view = View::factory('admin/site/news');

        $view->newsList =$newsList;

        $view->page= $page;

        $view->pages=$pages;

        $view->caption=$caption;

        $view->username=$username;

        $this->template->content =  $view;
    }
}
